package edu.uic.kott.activities;

import java.io.File;

import edu.uic.keyoutcomestrackertool.R;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


//Classes extend activity, if lots of buttons to listen then implement onClickListener as well
public class HomeScreen extends Activity implements OnClickListener{

	//On Create 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//Match view with activity
		setContentView(R.layout.home_screen);		

		//Call each button by identity and set on click listener (implemented so just 'this')
		Button enterViewClassesStudySessionsButton = (Button) findViewById(R.id.enterViewClassesStudySessionsButton);
		enterViewClassesStudySessionsButton.setOnClickListener(this);

		Button viewAllInstructors = (Button) findViewById(R.id.viewAllInstructorsButton);
		viewAllInstructors.setOnClickListener(this);


		Button viewActivities = (Button) findViewById(R.id.viewActivitiesButton);
		viewActivities.setOnClickListener(this);

		Button trackKeyOutcomes = (Button) findViewById(R.id.trackKeyOutcomesButton);
		trackKeyOutcomes.setOnClickListener(this);

		Button infoButton = (Button) findViewById(R.id.infoButton);
		infoButton.setOnClickListener(this);

		Button pdfButton = (Button) findViewById(R.id.pdfButton);
		pdfButton.setOnClickListener(this);

		Button profileButton = (Button) findViewById(R.id.studentProfileButton);
		profileButton.setOnClickListener(this);

	}


	//On click, check id, start activity
	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.enterViewClassesStudySessionsButton) {
			startActivity(new Intent(HomeScreen.this, Courses.class));
		}

		else if (v.getId() == R.id.viewAllInstructorsButton) {
			startActivity(new Intent(HomeScreen.this, Instructors.class));
		}

		else if (v.getId() == R.id.viewActivitiesButton) {
			startActivity(new Intent(HomeScreen.this, CourseActivities.class));
		}

		else if (v.getId() == R.id.trackKeyOutcomesButton) {
			startActivity(new Intent(HomeScreen.this, TrackKeyOutcomes.class));
		}

		else if (v.getId() == R.id.infoButton) {
			startActivity(new Intent(HomeScreen.this, About.class));
		}

		else if (v.getId() == R.id.studentProfileButton) {


			File f = new File(getFilesDir().getPath(), "studentProfile.xml");

			Log.i("File", f.toString());

			if (f.exists()) {
				startActivity(new Intent(HomeScreen.this, StudentProfileView.class));
			}
			else {
				startActivity(new Intent(HomeScreen.this, StudentProfileEdit.class));
			}
		}

		else if (v.getId() == R.id.pdfButton) {
			Intent pdfLink = new Intent(android.content.Intent.ACTION_VIEW);
			pdfLink.setData(Uri.parse("http://bestpracticestograduate.org/downloads.html"));
			startActivity(pdfLink);
		}
	}
}
